package pandabay.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import org.springframework.web.servlet.view.RedirectView;

import pandabay.service.ProductSearch;
import pandabay.service.PriceIncrease;
import pandabay.service.ProductManager;
import pandabay.service.SimpleProductManager;

public class SearchFormController extends HttpServlet {
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
		String searchString = request.getParameter("searchString");
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		
		ProductSearch ps = new ProductSearch();
		List searchResults = ps.searchProducts(searchString);
		System.out.println(searchResults.get(0).toString());
		
		Iterator it = searchResults.iterator();
		while(it.hasNext()) {
			out.println("We found: " + it.next());
		}
		
//		request.setAttribute("searchResults", searchResults);
//		RequestDispatcher view = request.getRequestDispatcher("searchResult.jsp");
		
//		response.sendRedirect("pandabay/searchResult.jsp");
//		view.forward(request, response);
		
	}

}
